<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
/**
 * 问答控制器
 */
class lottery extends MY_Controller {

    function explain() {
        $this->display('lottery/explain.html');
    }
    function detail() {
        $lottery_id= isset($_GET['lottery_id']) ? decrypt_lottery_id(trim($_GET['lottery_id'])) : "";
        $item = $this->db->query("select content from tan_go_shoplist where id = $lottery_id order by id desc limit 1")->row_array();
        if(!$item){
            $this->display('deleted/index.html');exit;
        }
        $this->assign("item",$item);
        $this->display('lottery/detail.html');
    }
    function count() {
        $lottery_id= isset($_GET['lottery_id']) ? decrypt_lottery_id(trim($_GET['lottery_id'])) : "";
        $item=$this->db->query("select tan_go_shoplist.*,tan_users.username,tan_users_info.nickname,tan_users_info.head_img from `tan_go_shoplist` left join tan_users on tan_users.user_id = tan_go_shoplist.q_uid  left join tan_users_info on tan_users_info.user_id = tan_go_shoplist.q_uid  where tan_go_shoplist.`id`='$lottery_id' LIMIT 1")->row_array();
        if(!$item){
            $this->display('deleted/index.html');exit;
        }
        //幸运号码计算的记录信息
        if($item['q_content']){
            $item_q_content = unserialize($item['q_content']);
            $keysvalue = $new_array = array();
            foreach($item_q_content as $k=>$v){
                $keysvalue[$k] = $v['time'];
                $h=date("H",$v['time']);
                $i=date("i",$v['time']);
                $s=date("s",$v['time']);
                list($timesss,$msss) = explode(".",$v['time']);
                $item_q_content[$k]['timeadd'] = $h.$i.$s.$msss;
                $item_q_content[$k]['time_str'] = date("Y-m-d H:i:s",substr($v['time'],0,10)).".".$msss;
                $user = $this->db->query("select nickname,head_img from tan_users_info where user_id = $v[uid] order by user_id desc limit 1")->row_array();
                $item_q_content[$k]['nickname'] = $user['nickname'];
                $item_q_content[$k]['head_img'] = $user['head_img'];
            }
            arsort($keysvalue);	//asort($keysvalue);正序
            reset($keysvalue);
            foreach ($keysvalue as $k=>$v){
                $item_q_content[$k]['index'] = sprintf("%03d",$k+1);
                $new_array[$k] = $item_q_content[$k];
            }
            $item['q_content'] = $new_array;
        }
        $this->assign("item",$item);
        $this->display('lottery/count.html');
    }    
}
